'    Copyright 2008 Jan Molnar <jan.molnar@abds.de>
'
'    This file is part of JCQ.

'    JCQ is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    JCQ is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with JCQ. If not, see <http://www.gnu.org/licenses/>.

Option Strict On

Public Class Identity
    Implements IIdentity

    Private values As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
    Private _Description As String
    Private _Identifier As String
    Private _ImageUrl As String

    Public Sub New(ByVal id As String)
        _Identifier = id
    End Sub

    Public Property Identifier() As String Implements IIdentity.Identifier
        Get
            Return _Identifier
        End Get
        Set(ByVal value As String)
            _Identifier = value
        End Set
    End Property

    Public Property Description() As String Implements IIdentity.Description
        Get
            Return _Description
        End Get
        Set(ByVal value As String)
            _Description = value
        End Set
    End Property

    Public Property ImageUrl() As String Implements IIdentity.ImageUrl
        Get
            Return _ImageUrl
        End Get
        Set(ByVal value As String)
            _ImageUrl = value
        End Set
    End Property

    Public Function GetAttribute(Of T)(ByVal key As IIdentityAttribute(Of T)) As T Implements IIdentity.GetAttribute
        Return DirectCast(GetAttribute(key.AttributeName), T)
    End Function

    Public Function GetAttributeNames() As String() Implements IIdentity.GetAttributeNames
        Return values.Keys.ToArray
    End Function

    Public Sub SetAttribute(Of T)(ByVal key As IIdentityAttribute(Of T), ByVal value As T) Implements IIdentity.SetAttribute
        SetAttribute(key.AttributeName, value)
    End Sub

    Public Sub SetAttribute(ByVal key As String, ByVal value As Object) Implements IIdentity.SetAttribute
        If values.ContainsKey(key) Then
            values(key) = value
        Else
            values.Add(key, value)
        End If
    End Sub

    Public Function GetAttribute(ByVal key As String) As Object Implements IIdentity.GetAttribute
        Return values(key)
    End Function

    Public Function HasAttribute(ByVal key As String) As Boolean Implements IIdentity.HasAttribute
        Return values.ContainsKey(key)
    End Function

    Public Function HasAttribute(Of T)(ByVal key As IIdentityAttribute(Of T)) As Boolean Implements IIdentity.HasAttribute
        Return HasAttribute(key.AttributeName)
    End Function
End Class
